fix: calculate total seconds from interval fields for extract(epoch)#19807
Merged
adriangb merged 5 commits intoapache:mainfrom Jan 16, 2026
Merged
fix: calculate total seconds from interval fields for extract(epoch)#19807adriangb merged 5 commits intoapache:mainfrom
extract(epoch)#19807adriangb merged 5 commits intoapache:mainfrom
Conversation
Jefffrey
approved these changes
Jan 14, 2026
Contributor
Jefffrey
left a comment
There was a problem hiding this comment.
Results seem consistent with DuckDB 👍
|
|
||
| fn epoch(array: &dyn Array) -> Result<ArrayRef> { | ||
| const SECONDS_IN_A_DAY: f64 = 86400_f64; | ||
| const DAYS_PER_MONTH: f64 = 30_f64; |
Contributor
There was a problem hiding this comment.
I suppose there's no easier way to define this for intervals 🤔
Contributor
Author
There was a problem hiding this comment.
Yes! I just followed the PostgreSQL-way for simplicity here, what do u think?
https://doxygen.postgresql.org/datatype_2timestamp_8h.html#ad35c6d425de4ccc4718c6ce7f4bfbba2
adriangb
approved these changes
Jan 15, 2026
martin-g
approved these changes
Jan 15, 2026
7d2c798 to
d73f19a
Compare
Contributor
|
Good to go 👍 |
Contributor
|
Thanks both! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Which issue does this PR close?
select extract(epoch from ('15 minutes')::interval)gives wrong result #19799.Rationale for this change
The epoch function incorrectly used
date_part(array, DatePart::Second)for intervals which only extracts the seconds component of the interval structure (0 for "15 minutes"), not the total seconds from all components.What changes are included in this PR?
Are these changes tested?
Yes. Added tests verifying correct conversion for all interval types and precision levels.
Are there any user-facing changes?
Yes.
extract(epoch from interval)now returns correct total seconds instead of 0.